import 'dart:io';

import '../../util/_base_export.dart';
import '../../util/_view_export.dart';

import 'package:url_launcher/url_launcher.dart';

import '../../util/app_util.dart';
import '../../blocs/cart.dart';

import 'package:tobias/tobias.dart';

class OtherUpgradePage extends StatelessWidget {
  Future<void> _urlLaunch(String url) async {
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Container(
        child: SingleChildScrollView(
          child: Column(
            // crossAxisAlignment: CrossAxisAlignment.start,
            // mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                height: 180.h,
                alignment: Alignment.center,

                decoration: BoxDecoration(
                  color: AppColor.yellowText,
                ),
                child: GestureDetector(
                  onTap: () {
                    // App.router.navigateTo(context, AppRoutes.loginSignin);
                    // App.router.navigateTo(context, AppRoutes.myApp);
                  },
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Image.asset('assets/account/guest_logo.png'),
                      SizedBox(
                        height: 5,
                      ),
                      Text('版本升级'),
                      Text('请点击下方链接更新至最新版本'),
                    ],
                  ),
                ),

                // ),
              ),
              _upgradeBlock(),
              if ((AppSession.platformConst['dl_url'] ?? '').isNotEmpty) _manualBlock(),
              // _contactUsBlock(),
            ],
            // );
            //   },
          ),
        ),
      ),
    );
    // )
  }

  Widget _upgradeBlock() {
    return Card(
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () async {
          await _urlLaunch(AppSession.platformConst['store_url']);
        },
        child: Container(
          height: 80.h,
          padding: EdgeInsets.symmetric(
            vertical: 24.h,
            horizontal: 24.w,
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: <Widget>[
                  Icon(
                    // MaterialCommunityIcons.cloud_download,
                    Icons.download_rounded,
                    color: AppColor.yellowText,
                    size: 26,
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 16.w, right: 0.w),
                    child: Text(
                      '自动升级',
                      style: TextStyle(color: AppColor.blackMain, fontSize: 15.sp),
                    ),
                  ),
                ],
              ),
              Icon(
                Icons.chevron_right,
                color: AppColor.blackMain,
                size: 30,
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _manualBlock() {
    return Card(
      child: GestureDetector(
        onTap: () async {
          await _urlLaunch(AppSession.platformConst['dl_url']);
        },
        child: Container(
          height: 80.h,
          padding: EdgeInsets.symmetric(
            vertical: 24.h,
            horizontal: 24.w,
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: <Widget>[
                  Icon(
                    // MaterialCommunityIcons.file_download,
                    Icons.download_sharp,
                    color: AppColor.yellowText,
                    size: 26,
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 16.w, right: 0.w),
                    child: Text(
                      'Android 手动下载 (不推荐)',
                      style: TextStyle(color: AppColor.blackMain, fontSize: 15.sp),
                    ),
                  ),
                ],
              ),
              Icon(
                Icons.chevron_right,
                color: AppColor.blackMain,
                size: 30,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
